<%@page import="java.util.Set"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@page import="java.io.File"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.BufferedInputStream"%>
<%@page import="java.io.DataInputStream"%>
<%@page import="java.io.PrintWriter"%>
<%@page import="java.io.FileOutputStream"%>
<%@page import="java.io.IOException"%>
<%@page import="java.io.FileNotFoundException"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>ICS Event Log</title>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css" />
        <script src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.js"></script>
    </head>
    <body>
        <div data-role="page">
 
            <div data-role="header" data-position ="fixed">
                <h1>ICS Event Log</h1>
            </div>

            <div data-role="content"> 
                <%
                String fileName=getServletContext().getRealPath("sample.log"); 
                try{
                    File f = new File(fileName);
                    InputStream in = new FileInputStream(f); 

                    BufferedInputStream bin = new BufferedInputStream(in); 

                    DataInputStream din = new DataInputStream(bin); 
                    StringBuffer sb=new StringBuffer(); 
                    while(f != null && din.available()>0) 
                        { 
                        sb.append(din.readLine() + "<br />"); 
                        } 

                    try {
                        if(f != null){
                            if(sb.length() == 0){
                                out.println("<b>Log file is empty</b>");
                            }

                            else{
                                out.println(sb.toString());
                            }
                        }
                    } catch(IOException e) { 
                       e.getMessage(); 
                    } 

                    in.close(); 
                    bin.close(); 
                    din.close(); 
                }
                catch(FileNotFoundException e){
                    out.println("<br /><b>No log file found</b><br />"); 
                }
                %>
            </div>
            
            <div data-role="footer">
                <h4>Trinity College Dublin 2012 </h4>
            </div>
        </div>
    </body>
</html>